package yawning.mew.cat;

import yawning.mew.sim.SimulationAction;

public class FeralChargeAction implements SimulationAction {
	CatModelSimState mState;
	double mCooldownAt;
	
	FeralChargeAction(CatModelSimState state) {
		mState = state;
	}
	
	@Override
	public double perform() {
		int cost = mState.mModel.feralChargeCost;

		if (mCooldownAt > mState.mSimUtil.getSimTime() || mState.energyTickEv.mEnergy < cost) return SimulationAction.ACTION_FAIL;

		// XXX: Only support this on the opener for now.
		//
		// To generalize support would require adding in stopping/restarting the swing timer
		// and a notion of distance from target, which would be... annoying.
		if (mState.isInCombat()) return SimulationAction.ACTION_FAIL;

		mCooldownAt = mState.mSimUtil.getSimTime() + mState.mModel.feralChargeCDDuration;
		mState.stampedeEv.run();

		mState.nrFeralCharge++;

		mState.energyTickEv.mEnergy -= cost;

		return 0.0;
	}
}
